package drive.Controller;

import drive.Model.TransactionOrder;
import drive.Service.ServiceInterface.TransactionOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//完成基础测试，2025.3.17
@RestController
@RequestMapping("/transactionorder")
public class TransactionOrderController {
    @Autowired
    private TransactionOrderService transactionOrderService;

    // 查询所有交易订单
    @GetMapping()
    public String selectAllOrders() {
        return transactionOrderService.findAll();
    }

    // 根据orderID查询交易订单
    @GetMapping("/{orderID}")
    public String selectOrderByOrderID(@PathVariable("orderID") int orderID) {
        return transactionOrderService.findByOrderID(orderID);
    }

    // 根据buyerID查询交易订单
    @GetMapping("/buyer/{buyerID}")
    public String selectOrdersByBuyerID(@PathVariable("buyerID") int buyerID) {
        return transactionOrderService.findByBuyerID(buyerID);
    }

    // 根据sellerID查询交易订单
    @GetMapping("/seller/{sellerID}")
    public String selectOrdersBySellerID(@PathVariable("sellerID") int sellerID) {
        return transactionOrderService.findBySellerID(sellerID);
    }

    // 根据itemID查询交易订单
    @GetMapping("/item/{itemID}")
    public String selectOrderByItemID(@PathVariable("itemID") int itemID) {
        return transactionOrderService.findByItemID(itemID);
    }

    // 新增交易订单
    @PostMapping()
    public String addOrder(@RequestBody TransactionOrder order) {
        return transactionOrderService.add(order);
    }

    // 更新交易订单
    @PutMapping()
    public String updateOrder(@RequestBody TransactionOrder order) {
        return transactionOrderService.update(order);
    }

    // 删除交易订单
    @DeleteMapping("/{orderID}")
    public String deleteOrder(@PathVariable("orderID") int orderID) {
        return transactionOrderService.delete(orderID);
    }
}